/* 
 * Created on 17. September 2008, 22:39
 *
 *      Copyright 2008 Oliver Eichner <o.eichner@gmail.com>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 3 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

/**
 * @file DeviceDetailDialog.cpp
 * Device Detail Dialog shows tableau-parm infos
 */
#include <gtkmm-2.4/gtkmm/box.h>
#include <gtkmm-2.4/gtkmm/window.h>

#include "DeviceDetailDialog.h"

/**
 * @brief The Detailed Device Dialog
 * Shows Detailed Informations on Devices, if they where found ;)
 * @param nDevice The Kernelname of a device
 */
DeviceDetailDialog::DeviceDetailDialog(Device nDevice)
: Gtk::Dialog("Device Details", true),
dd_frame("Device"),
dd_HBox(false, 8),
dd_Image(Gtk::Stock::HARDDISK, Gtk::ICON_SIZE_DIALOG) {

    stringstream sstr;
    string frameLabel;
    set_default_size(450, 400);
    frameLabel.append(nDevice.getDeviceName());
    //sstr >> frameLabel;
    frameLabel.insert(0, "Device details for ");
    if (!nDevice.getBridge_model().empty()) {
        frameLabel.append(" on ");
        frameLabel.append(nDevice.getBridge_model());
    }
    add_button(Gtk::Stock::SAVE, response_Save);
    //  add_button(Gtk::Stock::PRINT, response_Print);
    add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);

    dd_HBox.set_border_width(8);
    dd_frame.set_label(frameLabel);

    get_vbox()->pack_start(dd_HBox, Gtk::PACK_EXPAND_WIDGET);
    dd_HBox.pack_start(dd_Image, Gtk::PACK_SHRINK);
    // Device object

    // Device devinfo(nDevice);

    if (nDevice.getSizeMB() == 0) {
        cout << "Device not Found" << endl;
        dd_label.set_text("Device not found!!\nPlease press the refresh-button in the main window.");


        dd_HBox.pack_start(dd_label, Gtk::PACK_SHRINK);
    } else {

        dd_HBox.add(dd_frame);

        dd_TreeView.set_model(dd_refListStore = Gtk::ListStore::create(dd_Cols));

        Gtk::TreeModel::Row row = *(dd_refListStore->append());

        if (!nDevice.getBridge_chan_index().empty()) {
            row[dd_Cols.col_type] = "Bridge Information:";
            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "chan index";
            row[dd_Cols.col_value] = nDevice.getBridge_chan_index();

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "chan type";
            row[dd_Cols.col_value] = nDevice.getBridge_chan_type();

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "writes permitted";
            row[dd_Cols.col_value] = (nDevice.getBridge_writes_permitted() ? TP_YES : TP_NO);

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "declare write blocked";
            row[dd_Cols.col_value] = (nDevice.getBridge_declare_write_blocked() ? TP_YES : TP_NO);

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "declare write errors";
            row[dd_Cols.col_value] = (nDevice.getBridge_declare_write_errors() ? TP_YES : TP_NO);

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Bridge Serial";
            row[dd_Cols.col_value] = nDevice.getBridge_serial();

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Bridge Vendor";
            row[dd_Cols.col_value] = nDevice.getBridge_vendor();

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Bridge Model";
            row[dd_Cols.col_value] = nDevice.getBridge_model();

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Firmware Date";
            row[dd_Cols.col_value] = nDevice.getBridge_firmware_date();

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Firmware Time";
            row[dd_Cols.col_value] = nDevice.getBridge_firmware_time();


            row = *(dd_refListStore->append());
            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Drive Information";
            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Drive Vendor";
            row[dd_Cols.col_value] = nDevice.getBridge_drive_vendor();

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Drive Model";
            row[dd_Cols.col_value] = nDevice.getBridge_drive_model();

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Drive Serial";
            row[dd_Cols.col_value] = nDevice.getBridge_drive_serial();

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Drive Revision";
            row[dd_Cols.col_value] = nDevice.getBridge_drive_revision();

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Drive Size";
            row[dd_Cols.col_value] = nDevice.getSize();

            row = *(dd_refListStore->append());
            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "HPA/DCO/Security Information:";

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Security Support";
            row[dd_Cols.col_value] = (nDevice.getBridge_security_support() ? TP_YES : TP_NO);

            if (nDevice.getBridge_security_support()) {
                row = *(dd_refListStore->append());
                row[dd_Cols.col_type] = "Security in use";
                row[dd_Cols.col_value] = (nDevice.getBridge_security_in_use() ? TP_YES : TP_NO);
            }

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "HPA Support";
            row[dd_Cols.col_value] = (nDevice.getBridge_hpa_support() ? TP_YES : TP_NO);

            if (nDevice.getBridge_hpa_support()) {
                row = *(dd_refListStore->append());
                row[dd_Cols.col_type] = "HPA in use";
                row[dd_Cols.col_value] = (nDevice.getBridge_hpa_in_use() ? TP_YES : TP_NO);
            }

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "DCO Support";
            row[dd_Cols.col_value] = (nDevice.getBridge_dco_support() ? TP_YES : TP_NO);

            if (nDevice.getBridge_dco_support()) {
                row = *(dd_refListStore->append());
                row[dd_Cols.col_type] = "DCO in use";
                row[dd_Cols.col_value] = (nDevice.getBridge_dco_in_use() ? TP_YES : TP_NO);
            }

            if (nDevice.getBridge_hpa_support() | nDevice.getBridge_dco_support()) {
                row = *(dd_refListStore->append());
                row[dd_Cols.col_type] = "Drive Capacity";
                row[dd_Cols.col_value] = nDevice.getBridge_drive_capacity();
            }
            if (nDevice.getBridge_hpa_support()) {
                row = *(dd_refListStore->append());
                row[dd_Cols.col_type] = "HPA Capacity";
                row[dd_Cols.col_value] = nDevice.getBridge_hpa_capacity();
            }
            if (nDevice.getBridge_dco_support()) {
                row = *(dd_refListStore->append());
                row[dd_Cols.col_type] = "DCO Capacity";
                row[dd_Cols.col_value] = nDevice.getBridge_dco_capacity();

                row = *(dd_refListStore->append());
                row[dd_Cols.col_type] = "DCO Challenge Key";
                row[dd_Cols.col_value] = nDevice.getBridge_dco_challenge_key();
            }
        } else {
            row[dd_Cols.col_type] = "Drive Information:";
            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Drive Vendor";
            row[dd_Cols.col_value] = nDevice.getVendor();

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Drive Model";
            row[dd_Cols.col_value] = nDevice.getModel();

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Drive Serial";
            row[dd_Cols.col_value] = nDevice.getSerial();

            //        row = *(dd_refListStore->append());
            //        row[dd_Cols.col_type] = "Drive Revision";
            //        row[dd_Cols.col_value] = nDevice.getRevision();

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Drive Size";
            row[dd_Cols.col_value] = nDevice.getSize();

            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Drive Blocksize";
            row[dd_Cols.col_value] = nDevice.getSizeBLK();

        }

        if (!nDevice.getComment().empty()) {
            row = *(dd_refListStore->append());
            row = *(dd_refListStore->append());
            row[dd_Cols.col_type] = "Comment:";
            row[dd_Cols.col_value] = nDevice.getComment();
        }


        dd_TreeView.append_column("Type", dd_Cols.col_type);
        dd_TreeView.append_column("Value", dd_Cols.col_value);

        dd_TreeView.set_rules_hint();


        dd_ScrolledWindow.add(dd_TreeView);
        dd_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
        dd_frame.add(dd_ScrolledWindow);
    }
    show_all();
}

DeviceDetailDialog::~DeviceDetailDialog() {

}

